package com.six.JacksonOperation;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.six.entity.Person;

import java.io.IOException;
import java.util.List;

/**
 * ClassName:JsonToJava
 * Package:com.six
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/27 - 22:48
 * @Version:v1.0
 */
//JSON数组字符串-->List
public class JsonToJava6 {

    public static void main(String[] args) throws IOException {
        String json = "[{\"name\":\"swx\",\"age\":18,\"skillsList\":[\"java\",\"python\",\"php\"]}," +
                "{\"name\":\"博尔特\",\"age\":55,\"skillsList\":[\"短跑\",\"两百米跑\"]}," +
                "{\"name\":\"迪迦\",\"age\":1500,\"skillsList\":[\"打怪兽\",\"射击\"]}]";
        ObjectMapper objectMapper = new ObjectMapper();
        List<Person> personList = objectMapper.readValue(json, new TypeReference<List<Person>>() {
        });
        //Person(name=swx, age=18, skillsList=[java, python, php])
        //Person(name=博尔特, age=55, skillsList=[短跑, 两百米跑])
        //Person(name=迪迦, age=1500, skillsList=[打怪兽, 射击])
        personList.forEach(item -> {
            System.out.println(item);
        });
    }
}
